<template>
    <div id="background">
        <el-container>
            <el-header id="shiCaoHead">
                <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                    <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                    <img v-bind:src="backIcon" class="backSize" @click="back"/>
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol"> 
                    <span class="titleSize">实操培训</span>
                    </el-col>
                   
                </el-row>
            </el-header>
            <el-main style="backgroundColor:#ffffff">
                <el-container>
                    <el-header id="shiCaoTab">
                        <van-tabs v-model="activeGongZhong" swipeable animated color="#53cdf5"  @change="showGongZhong" style="width:100%">
                            <van-tab v-for="index in gongZhongs" v-bind:key="index.professionId" :title="index.professionName" :name="index.professionId"></van-tab>
                        </van-tabs>
                    </el-header>
                    <el-main>
                                 <div v-for="shiCao in shiCaos" :key="shiCao.id" @click="goToPeiXunIntroduce(shiCao.id)"  v-infinite-scroll="load" infinite-scroll-disabled="disabled">
                                        <el-col :xs="12" :sm="12" :md="12">
                                            <el-card style="margin-left: 10px; margin-right: 10px;margin-top:10px;height:130px" :body-style="{ padding: '0px'}" >
                                                <div  style="position:relative;text-align:center;">
                                                    <!-- <img v-bind:src="shiCao.trainPicture" style="width:100%;height:85px"/> -->
                                                    <el-image
                                                        style="width: 100%; height: 85px;border-radius:5px"
                                                        :src="shiCao.trainPicture"
                                                        fit="cover">
                                                    </el-image>
                                                    <div style="position:absolute;left:0;top:60px;right:0;bottom:0">
                                                        <!-- <el-row >
                                                            <span class="words noHuanHang" >{{shiCao.name}}</span>
                                                        </el-row> -->
                                                         <el-row >
                                                            <el-col v-if="shiCao.tag" :xs="6" :sm="6" :md="6" :offset="18">
                                                                <span class="reMenTag">热门</span>
                                                            </el-col>
                                                            <el-col v-else :xs="6" :sm="6" :md="6" :offset="18">
                                                                <span class="zuiXinTag">最新</span>
                                                            </el-col>
                                                        </el-row>
                                                    </div>
                                                </div>
                                                <div>
                                                <el-row >
                                                    <el-col class="imgCol">
                                                        <span class="words noHuanHang" >{{shiCao.name}}</span>
                                                    </el-col>
                                                </el-row>
                                                <el-row type="flex">
                                                    <el-col  :xs="2" :sm="2" :md="2" :offset="1">
                                                        <i class="el-icon-user-solid" style="font-size:12px;color:#707070"></i>
                                                    </el-col>
                                                    <el-col  :xs="6" :sm="6" :md="6" >
                                                        <span style="font-size:12px" class="words">{{shiCao.count}}</span>
                                                    </el-col>
                                                    <el-col  :xs="12" :sm="12" :md="12" :offset="3">
                                                        <span style="font-size:12px" class="words">查看更多>></span>
                                                    </el-col>
                                                </el-row>
                                                </div>
                                            </el-card>
                                        </el-col>
                                </div>

                    </el-main>
                    <div style="height:5px;backgroundColor:#fff"></div>
                    <div v-if="loading" class="imgCol">
                        <span class="words" style="font-size:14px">加载中...</span>
                    </div>
                    <div v-if="noMore" class="imgCol">
                        <span class="words" style="font-size:14px">没有更多了...</span>
                    </div>
                </el-container>
            </el-main>
        </el-container>
    </div>
</template>
<script>
import stickySlot from '../common/stickySlot/stickySlot.vue'
import backIcon from '../../assets/img/mine/geRenZhongXin/back.png'
import { Toast } from 'vant';
import { setTimeout } from 'timers';
// import backgorund from '../background/background'
// import MyHeader from '../common/MyHeader/MyHeader'
export default {
    // components:{
    //     backgorund,
    //     MyHeader
    // },
    data(){
        return{
            //绑定加载状态是否显示
            loading: false,
            backIcon:backIcon,
            //绑定tab头的对应参数
            activeGongZhong:'',
            gongZhongs:[],
            //绑定refresh的对应参数
            isLoading: false,
            //绑定list的对应参数
            loading: false,
            finished: false,
            shiCaos:[],
            shiCaoInfo:{
                //对应工种的id
                id:1,
                //该工种下对应的题库总数
                total:0,
                professionId:1,
                pageNo:1,
                pageSize:8,
            }
        }
    },
    computed: {
      noMore () {
        return this.shiCaos.length>=this.shiCaoInfo.total;
      },
      disabled () {
        return this.loading || this.noMore;
      }
    },
    mounted(){
          this.getZhiYes();
          this.getShiCaos();
       // var normalHeight=sessionStorage.getItem('normalHeight');
       var normalHeight=document.documentElement.clientHeight;

        var bg = document.getElementById("background");
       // normalHeight=document.documentElement.clientHeight;
        console.log("height:"+normalHeight);
        bg.style.height = normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";

        var head=document.getElementById("shiCaoHead");
        var headHeight=normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

    },
    methods:{

        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        goToPeiXunIntroduce(trainId){
           // console.log("intro");
           console.log("trainId:"+trainId);
           this.$router.push({
               path:'/shiCao/introduce',
               query:{
                   trainId:trainId
               }
           })
        },
        //获取工种种类
        getZhiYes(){
            var URL=this.IP.IP+'/visitor/getProfessionInformation';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.gongZhongs=response.data.data.professionInformation;
                    this.shiCaoInfo.professionId=this.gongZhongs[0].professionId;
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        //选择工种不同时触发
        showGongZhong(id){
            console.log("工种：");
            this.finished=false;
            this.shiCaos=[];
            this.shiCaoInfo.professionId=id;
            this.shiCaoInfo.pageNo=0;
            this.getShiCaos();
            console.log(this.shiCaoInfo.professionId);
        },
        //获取实操预览
        getShiCaos(){
            var URL=this.IP.IP+'/train/getTrainOutline';
            console.log(URL);
            console.log(this.shiCaoInfo);
            this.$ajax({
                method:'get',
                url:URL,
                params:{
                    professionId:this.shiCaoInfo.professionId,
                    pageNo:this.shiCaoInfo.pageNo,
                    pageSize:this.shiCaoInfo.pageSize
                }
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    var i=0;
                    for(i=0;i<response.data.data.info.length;i++){
                        this.shiCaos.push(response.data.data.info[i]);
                    }
                    // this.tiKus=response.data.data.info;
                    console.log(this.shiCaos);
                    this.shiCaoInfo.total=response.data.data.total;
                    console.log(this.shiCaoInfo.total);
                    if(this.shiCaos.length>=this.shiCaoInfo.total){
                        console.log("finish");
                        this.finished=true;
                        this.loading=false;
                    }
                }else{
                    this.finished=true;
                    this.loading=false;
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        load () {
            this.loading = true
            setTimeout(() => {
                this.shiCaoInfo.pageNo++;
                this.getShiCaos();
                this.loading = false;
            }, 2000)
        },
    }
    
}
</script>
<style>
.end{
    display: flex;
    justify-content: flex-end;
}
.noHuanHang{
    white-space: nowrap;
    overflow: hidden;
}
.el-main{
    padding: 0px;
}
.el-header{
    padding: 0px;
}
.shiCaoSmallWords{
    color: #707070;
    font-size:8px;
}
.words{
    color:#909090;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
#shiCaoHead{
    background-color: #53cdf5;
    color: #707070;
}
.reMenTag{
  border: 1px solid #53cdf5;
  color: #53cdf5;
  background-color: rgb(255,255,255,0);
  font-size: 6px;
  border-radius: 3px;
  padding: 1px;
}
.zuiXinTag{
  border: 1px solid #F16161;
  color: #F16161;
  background-color: rgb(255,255,255,0);
  font-size: 6px;
  border-radius: 3px;
  padding: 1px;
}
.backSize{
    height: 26px;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
}
</style>
